package com.config;

import com.condition.EnergyCarCondition;
import com.condition.OilCarCondition;
import com.entity.*;
import org.springframework.context.annotation.*;


@Configuration  //配置注解

/*XML形式：通过扫描器  将@Component等注解所在包 扫描

ComponentScan:只对三层组件负责
给扫描器指定规则：
    过滤类型：FilterType.ANNOTATION,CUSTOM
    ANNOTATION：三层注解类型@Controller、@Service、@Repository-》@Component
    excludeFilters：排除
    includeFilters：有默认行为，可以通过userDefaultFilters=false禁止
    ASSIGNABLE_TYPE:具体的类（StudentService.class）
区分：
ANNOTATION:Controller.class指的是所有标有@Controller的类
ASSIGNABLE_TYPE：指的是具体的一个类StudentController.class

CUSTOM自定义：

*/

//@ComponentScan(value = "com",excludeFilters ={@ComponentScan.Filter(type = FilterType.ANNOTATION,value ={Service.class, Repository.class} )} )

//@ComponentScan(value = "com",includeFilters ={@ComponentScan.Filter(type = FilterType.ANNOTATION,value ={Service.class, Repository.class})},useDefaultFilters = false)

//@ComponentScan(value = "com",includeFilters ={@ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE,value ={StudentController.class, Repository.class})},useDefaultFilters = false)
//@ComponentScan(value = "com",includeFilters ={@ComponentScan.Filter(type = FilterType.CUSTOM,value ={MyFilter.class, Repository.class})},useDefaultFilters = false)



public class MyConfig {

    @Bean //id="myStudent" id默认就是方法名
    @Scope("singleton")
    @Lazy
    public Student myStudent(){
        Student student=new Student(20,"zs100",38);
        student.setAddress(new Address("xa","bj"));
        return student;


    }


    @Bean
    @Conditional(OilCarCondition.class)
    public Car oilCar(){
        return new OilCar();
    }

    @Bean
    @Conditional(EnergyCarCondition.class)
    public Car energyCar(){
        return new EnegerCar();
    }





}
